package com.dabaozhan.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class RandomUtils {

	/**
	 * 获取4位随机数
	 * @return
	 */
	public static int random() {
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (9999 - 1000 + 1)) + 1000;
		return rannum;
	}
	
	/**
	 * 订单随机数
	 * @return
	 */
	public static String random6() {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		String time = df.format(new Date());
		
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 1000000;
		time = time + rannum;
		return time;
	}

	public static String randomStr(){
		StringBuilder sb = new StringBuilder() ;
		int i = 10;//控制字符长度
		for (int j = 0; j < i; j++) {
			//生成一个97-122之间的int类型整数--为了生成小写字母
			int intValL = (int)(Math.random()*26+97);
			//生成一个65-90之间的int类型整数--为了生成大写字母
			int intValU = (int)(Math.random()*26+65);
			//生成一个30-39之间的int类型整数--为了生成数字
			int intValN = (int)(Math.random()*10+48);

			int intVal = 0;
			int r = (int)(Math.random()*3);

			if(r==0) {
				intVal = intValL;
			}else if (r==1) {
				intVal = intValU;
			}else {
				intVal = intValN;
			}

			sb.append((char) intVal);
		}
		System.out.println(sb);

		return sb.toString();
	}
}
